package com.st.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.st.entity.*;
import com.st.mapper.IOrderMapper;
import com.st.mapper.IScenicEvaluationMapper;
import com.st.service.IOrderService;
import com.st.service.IScenicEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class ScenicEvaluationServiceImpl extends ServiceImpl<IScenicEvaluationMapper, ScenicEvaluation> implements IScenicEvaluationService {
    @Autowired
    private IScenicEvaluationMapper scenicEvaluationMapper;

    @Override
    public PageResult<ScenicEvaluation> findScenicEvaluations(PageDTO<ScenicEvaluation> pageDTO) {
        if (pageDTO == null) {
            return new PageResult<ScenicEvaluation>(false, "查询失败", null, null, null);
        }
        IPage<ScenicEvaluation> iPage = new Page<>(pageDTO.getPage(), pageDTO.getLimit());
        ScenicEvaluation data = pageDTO.getData();
        QueryWrapper<ScenicEvaluation> queryWrapper = new QueryWrapper<>(pageDTO.getData());
        if (!StringUtils.isEmpty(data.getScenicId())) {
            queryWrapper.eq("scenic_id", data.getScenicId());
        }
        if (!StringUtils.isEmpty(data.getTags())) {
            queryWrapper.eq("tags", data.getTags());
        }
        IPage<ScenicEvaluation> pageInfo = scenicEvaluationMapper.findScenicEvaluation(iPage, pageDTO.getData());
        PageResult pageResult = new PageResult<>();
        pageResult.setSuccess(true);
        pageResult.setData(pageInfo.getRecords());
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setMsg("查询成功");
        return pageResult;
    }

    @Override
    public Result delOne(ScenicEvaluation scenicEvaluation) {
        QueryWrapper<ScenicEvaluation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",scenicEvaluation.getId());
        int delete = scenicEvaluationMapper.delOne(scenicEvaluation.getId());
        return delete==1?new Result(true,"删除成功"):new Result(false,"删除失败");
    }
}
